package cn.edu.hqu.javaee.web;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import cn.edu.hqu.javaee.domain.Choose;
import cn.edu.hqu.javaee.domain.Course;
import cn.edu.hqu.javaee.domain.Personal;
import cn.edu.hqu.javaee.domain.User;
import cn.edu.hqu.javaee.domain.Course.Type;
import cn.edu.hqu.javaee.repository.ChooseRepository;
import cn.edu.hqu.javaee.repository.CourseRepository;
import cn.edu.hqu.javaee.repository.PersonalRepository;
import cn.edu.hqu.javaee.repository.UserRepository;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
@RequestMapping("/result")
public class ResultController {
	private final CourseRepository courseRepo;
	private PersonalRepository personalRepo;
	private ChooseRepository chooseRepo;
	private UserRepository userRepo;
	
	@Autowired
	public ResultController(
			CourseRepository courseRepo,
			PersonalRepository personalRepo,
			ChooseRepository chooseRepo,
			UserRepository userRepo
			) {
		this.courseRepo = courseRepo;
		this.personalRepo = personalRepo;
		this.chooseRepo = chooseRepo;
		this.userRepo=userRepo;
	}
	
	@GetMapping
	public String showResult(Model model) {
		List <Personal> personal = new ArrayList<>();
		personalRepo.findAll().forEach(i -> personal.add(i));
		List<Choose> choose = new ArrayList<>();
		chooseRepo.findAll().forEach(i -> choose.add(i));
		List<User> user = new ArrayList<>();
		userRepo.findAll().forEach(i -> user.add(i));
	    
	    model.addAttribute("choose",choose);
		model.addAttribute("personal",personal);
		model.addAttribute("user",user);
		log.info("personal: "+personal);
		log.info("choose: "+choose);
		log.info("user: "+user);
		System.out.println(user);
		
		return "last"; 
	}
}
